<?php


namespace app\admin\controller;


use app\admin\validate\RoomValidate;
use app\BaseController;
use app\model\Room;
use app\service\RoomService;
use think\App;

class RoomController extends BaseController
{
    private $service;

    public function __construct(App $app)
    {
        $this->service = new RoomService();
        parent::__construct($app);
    }

    public function getRoom(Room $room){
        return $this->returnJson($this->service->getRoom($room->id));
    }

    public function getRoomList(){
        $param = $this->request->param(['page' => '1' , 'limit' => '10']);
        return $this->returnJson($this->service->getRoomList(
            $param['page'] , $param['limit']
        ));
    }

    public function editRoom(Room $room){
        $param = $this->request->param(
            ['content' , 'type' , 'describe' , 'status' , 'deposit' , 'img_url' , 'price' , 'hotel_id']
        );
        return $this->returnJson($this->service->editRoom($room->id , $param));
    }

    public function deleteRoom(Room $room){
        $this->service->deleteRoom($room->id);
        return $this->returnJson();
    }

    public function addRoom(){
        $param = $this->request->param(['content' , 'type' , 'describe' , 'status' , 'deposit' , 'img_url' , 'price' , 'hotel_id']);
        validate(RoomValidate::class)
            ->scene('addRoom')
            ->check($param);
        return $this->returnJson($this->service->addRoom(
            $param['content'] , $param['type'] , $param['describe'] , $param['status'] , $param['deposit'] , $param['img_url'] , $param['price'] , $param['hotel_id']
        ));
    }
}